Skip to content

fix: don't redirect in forks#16292

Open
dummdidumm wants to merge 11 commits into
version-3from
fork-redirect-fix-version-3
Open

fix: don't redirect in forks#16292
dummdidumm wants to merge 11 commits into
version-3from
fork-redirect-fix-version-3

Conversation

@dummdidumm

Copy link
Copy Markdown
Member

This prevents a redirect that a remote function could do from doing a navigation in a fork. Leverages Svelte's new forking methods from sveltejs/svelte#17217 (no longer needs those, but having committed/discarded would be nice)

It's implemented by putting the context into fork, pulling it out on remote function invocation to check if we're in a fork (TODO what if you have it invoked elsewhere and you just await it in a fork context?), put that into a map, and pull it out of there when a redirect occurs to check if the remote function is only called in context of that fork, and if so instead of redirecting we tell the SvelteKit router that this new route will redirect elsewhere. In the future we could follow that redirect and run it in the fork, but this is good enough for now and ties nicely into the current SvelteKit router.

Fixes #14935

dummdidumm and others added 9 commits April 3, 2026 22:13
This prevents a redirect that a remote function could do from doing a navigation in a fork.

It's implemented by putting the context into fork, pulling it out on remote function invocation to check if we're in a fork, put that into a map, and pull it out of there when a redirect occurs to check if the remote function is only called in context of that fork, and if so instead of redirecting we tell the SvelteKit router that this new route will redirect elsewhere. In the future we could follow that redirect and run it in the fork, but this is good enough for now and ties nicely into the current SvelteKit router.

Fixes #14935
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/kit@2.69.2

### Patch Changes

- fix: set `define` values on `globalThis` when running Vitest
([#16246](#16246))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
The action won't run unless it's on `main` so
#16254 needs to be backported. Not
sure if the instrumentation test app and job also needs to be backported
for the one on `version-3` to run
@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 9, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from d9e61fe:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d9e61fec11f2a475957b055ecb245fd5fcd0e09f

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16292

@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d9e61fe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dummdidumm
dummdidumm changed the base branch from fork-redirect-fix to version-3 July 9, 2026 14:25
@svelte-docs-bot

Copy link
Copy Markdown

@dummdidumm dummdidumm mentioned this pull request Jul 9, 2026
5 tasks
@dummdidumm dummdidumm added this to the 3.0 milestone Jul 9, 2026
@dummdidumm

Copy link
Copy Markdown
Member Author

I wonder if we can use getBatch which I'm POCing in Svelte for this - the query would get his context batch back on resume, and can then say "oh this is a fork I should not use goto instead I should do X"

let data = $derived({${levels.map((l) => `'${l}': data_${l}`).join(', ')}});

if (browser) {
setContext('__sveltekit_fork', () => fork);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we use context here rather than just importing from a shared module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote functions: Prefetching prematurely tiggers redirect, disabling it subsequently

3 participants